package com.yricky.indesk.utils

import android.content.ComponentName
import android.content.Intent
import android.graphics.drawable.Drawable
import com.yricky.indesk.app
import com.yricky.indesk.model.pojo.AppEntrance

/**
 * @author Yricky
 * @date 2021/12/26
 */
fun AppEntrance.isEmpty():Boolean = pkgName.isEmpty() || activityName.isEmpty()
fun AppEntrance.isValid():Boolean = pkgMgr.queryIntentActivities(this.asIntent(),0).isNotEmpty()
fun AppEntrance.asIntent(): Intent = Intent().apply {
    component = ComponentName(pkgName,activityName)
}
fun AppEntrance.name():String = pkgMgr.queryIntentActivities(this.asIntent(),0).let{
    it.lastOrNull()?.activityInfo?.loadLabel(pkgMgr).toString()
}

fun AppEntrance.icon():Drawable? = pkgMgr.queryIntentActivities(this.asIntent(),0).let{
    it.lastOrNull()?.activityInfo?.loadIcon(pkgMgr)
}

